package com.lottery.im.module.chat.adapter;

import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lottery.im.R;
import com.lottery.im.module.tim.model.GroupMemberProfile;
import com.lottery.im.module.tim.model.SectionGroupMemberInfo;
import com.lottery.im.util.transformations.CropCircleTransformation;
import java.util.List;

public class SelectGroupMemberAdapter
    extends BaseSectionQuickAdapter<SectionGroupMemberInfo, BaseViewHolder> {

  private List<String> mSelectIds;

  /**
   * Same as QuickAdapter#QuickAdapter(Context,int) but with
   * some initialization data.
   *
   * @param data A new list is created out of this one to avoid mutable list
   */
  public SelectGroupMemberAdapter(List<SectionGroupMemberInfo> data, List<String> selectIds) {
    super(R.layout.item_group_member_list, R.layout.header_grouplist, data);
    this.mSelectIds = selectIds;
  }

  @Override protected void convertHead(BaseViewHolder helper, SectionGroupMemberInfo item) {
    helper.setText(R.id.tv_title, item.header);
  }

  @Override protected void convert(BaseViewHolder helper, SectionGroupMemberInfo item) {
    GroupMemberProfile memberProfile = item.t;
    if (mSelectIds.contains(memberProfile.getIdentify())) {
      helper.setImageResource(R.id.iv_status, R.drawable.icon_xz_selected);
    } else {
      helper.setImageResource(R.id.iv_status, R.drawable.icon_xz_nomal);
    }
    ImageView ivPortrait = helper.getView(R.id.iv_portrait);
    Glide.with(mContext)
        .load(memberProfile.getAvatarUrl())
        .apply(new RequestOptions()
            .bitmapTransform(new CropCircleTransformation())
            .placeholder(R.drawable.icon_conversation_de)
            .error(R.drawable.icon_conversation_de))
        .into(ivPortrait);

    helper.setText(R.id.tv_name, memberProfile.getName());
  }

  public void setSelectIds(List<String> selectIds, int position) {
    mSelectIds = selectIds;
    notifyItemChanged(position);
  }
}
